<!DOCTYPE html>
<html lang="zh-CN">

<head>
    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1,user-scalable=0">
    <!-- 上述3个meta标签*必须*放在最前面，任何其他内容都*必须*跟随其后！ -->
    <title>添加老师</title>

    <!-- Bootstrap -->
    <link rel="stylesheet" href="static/bootstrap-3.4.1/css/bootstrap.css">
    <link rel="stylesheet" href="static/bootstrap-3.4.1/css/bootoast.css">
    <!-- jQuery (Bootstrap 的所有 JavaScript 插件都依赖 jQuery，所以必须放在前边) -->
    <script src="static/bootstrap-3.4.1/js/jquery-3.6.0.min.js"></script>
    <!-- 加载 Bootstrap 的所有 JavaScript 插件。你也可以根据需要只加载单个插件。 -->
    <script src="static/bootstrap-3.4.1/js/bootstrap.js"></script>
    <script src="./static/bootstrap-3.4.1/js/bootoast.js"></script>
    <style>
        * {
            margin: 0;
            padding: 0;
        }

        main .myform {
            width: 30%;
            margin-left: 40px;
        }

        main p {
            display: block;
            width: 100%;
            /* position: absolute;
            bottom: 20px; */
            text-align: center;
            margin: 20px 0;
        }

        .footer {
            position: absolute;
            left: 0;
            right: 0;
            bottom: 10px;
            color: #666;
            text-align: center;
        }
    </style>
</head>

<body>
<div class="container-fluid my-container">
    <main>
        <!-- 路径导航 -->
        <ol class="breadcrumb" style="margin-top:5px;">
            <li><a href="#">主页</a></li>
            <li><a href="#">教师管理</a></li>
            <li class="active">添加老师</li>
        </ol>
        <!-- 表单 -->
        <div class="myform">
            <form>
                <div class="form-group">
                    <label for="rNum">房<span style="color:transparent;user-select: none;">隐藏</span>间<span style="color:transparent;user-select: none;">隐藏</span>号：</label>
                    <input type="text" class="form-control" name="rNum" id="rNum" placeholder="请输入房间号">
                </div>


                <div class="form-group">
                    <label for="type">房间类型：</label>
                    <select class="form-control" id="type">

                    </select>
                </div>
                <button type="button" class="btn btn-success" onclick="save()">保存</button>
            </form>

        </div>
    </main>
    <!-- 尾部 -->
    <div class="footer">技术支持:西安粤嵌信息科技有限公司</div>
</div>
<script>
    $(function(){
        loadTypes();
    })
    function loadTypes(){
        $.getJSON("/type/selectAll",function(data){
            $("#type").empty();
            let options = `<option value="0"readonly>请选择房间类型</option>`
            for (let type of data) {
                options += `<option value="${type.id}">${type.tName}</option>`
            }
            $("#type").append(options);
        })
    }
    function save() {
        let rNum = $("#rNum").val();
        let rType = $("#rType").val();
        $.post("/room/insertOne",{"rNum":rNum,"rType":rType},function(data){
            if(data){
                bootoast({
                    message:"添加成功！",
                    position:"top",
                    timeout:2,
                    type:"success"
                })
            }else{
                bootoast({
                    message:"添加失败！",
                    position:"top",
                    timeout:2,
                    type:"danger"
                })
            }
        })
    }
</script>
</body>
</html>